package com.ynny.dao;

import com.ynny.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class UserDaoImpl implements UserDao {
    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public int insertUser(User user) {
        String sql = "insert into user(id,number,password) values(?,?,?)";
        int update = jdbcTemplate.update(sql, user.getId(), user.getNumber(), user.getPassword());
        return update;
    }

    @Override
    public List<User> selectUserByUserName(String userName) {
        String sql = "select * from user where number = ?";
        List<User> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<User>(User.class), userName);
        return query;
    }
}
